import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request, Sse } from '@nestjs/common';
import { ChatService } from './chat.service';
import { CreateChatDto } from './dto/create-chat.dto';
import { JwtAuthGuard } from 'src/auth/jwt.guard';

@Controller('chat')
export class ChatController {
  constructor(private readonly chatService: ChatService) { }

  @Get('/history')
  @UseGuards(JwtAuthGuard)
  history(@Request() req) {
    return this.chatService.getChatHistory(req.user.sub);
  }

  @Post('/bd')
  @UseGuards(JwtAuthGuard)
  create(@Request() req, @Body() createChatDto: CreateChatDto) {
    createChatDto.userId = req.user.sub
    return this.chatService.create(createChatDto);
  }

  @Post('/bdv2')
  @UseGuards(JwtAuthGuard)
  @Sse()
  createV2(@Request() req, @Body() createChatDto: CreateChatDto) {
    createChatDto.userId = req.user.sub
    return this.chatService.createV2(createChatDto);
  }

  @Post('/restart')
  @UseGuards(JwtAuthGuard)
  restart(@Request() req) {
    return this.chatService.restartChat(req.user.sub);
  }
}
